package com.gqb.nio;

import java.nio.ByteBuffer;


public class nioBufferSlice {
	public static void main(String[] args) {
		ByteBuffer buffer=ByteBuffer.allocate(10);
		for (int i = 0; i < buffer.capacity(); i++) {
			buffer.put(i, (byte) ((i+1)*2));
		}
		buffer.position(3);
		buffer.limit(7);
		ByteBuffer slice= buffer.slice();
		for (int i = 0; i < slice.capacity(); i++) {
			slice.put(i, (byte) (slice.get(i)+1));
		}
		buffer.asReadOnlyBuffer();
		buffer.position(0);
		buffer.limit(9);
		while(buffer.hasRemaining()){
			System.out.println(buffer.get());
		}
	}
}
